<template>
    <div class="insurance">
        <div class="card-list">
            <van-pull-refresh v-model="isLoading" @refresh="onRefresh">
                <van-list v-model="loading" :finished="finished" finished-text="没有更多了" @load="onLoad">
                    <!-- <van-list v-model="loading" :finished="finished" finished-text="没有更多了" @load="onLoad"> -->
                    <div v-for="(item,index) in listSource" :key="index" class="card">
                        <div class="card-top" :style="{backgroundImage: 'url(' + imgUrl1 + ')'}">
                            <div class="card-title">
                                <div>{{item.company_name}}</div>
                                <div class="">{{item.goods_name}}</div>
                            </div>
                            <div class="single-line">地址：{{item.company_address}}</div>
                            <div class="single-line">联系电话：{{item.company_mobile}}</div>
                            <div class="mtext-line">产品价格：{{item.price}}</div>
                            <div class="mtext-line">客户费用结余：{{item.balance}}</div>
                            <!--                        <div class="single-line">所属业务：{{item.yw_name}}</div>-->
                            <!--                        <div class="single-line">所属客服：{{item.kf_name}}</div>-->
                        </div>
                        <div class="card-btn" :style="{backgroundImage: 'url(' + imgUrl2 + ')' }">
                            <div v-if="item.is_invoice==1||item.is_invoice==2" :class="[item.is_invoice == 2 ?'gray-color':'']" @click="showPop(item)">
                                {{item.is_invoice== 1 ? '确认开票':'查看开票信息'}}
                            </div>
                            <div v-else class="gray-color">无需开票</div>
                            <div v-if="item.receive_state!==0" :class="item.receive_state==1?'':'gray-color'" @click="goConfirmMoney(item)">{{item.receive_state==1?'确认收款':'已收款'}}</div>
                            <!-- <div v-if="item.payment_status==0" @click="goConfirmMoney(item)">确认收款</div> -->
                            <!-- <div v-else class="gray-color">已收款</div> -->
                            <div :class="[item.is_invoice == 1 ?'gray-color':'']" @click="goBillingInfo(item)">开票信息
                            </div>
                        </div>
                    </div>
                </van-list>
            </van-pull-refresh>
        </div>
    </div>
</template>

<script>
export default {
    name: "jrAdvisory",
    data() {
        return {
            listSource: [],
            page: 1,
            limit: 10,
            isLoading: false,
            imgUrl1: require('../../../assets/img/card_bg1.png'),
            imgUrl2: require('../../../assets/img/card_bg2.png'),
            list: [],
            loading: false,
            finished: false,
            isPop: false,
            button1: false,
        }
    },
    methods: {
        onRefresh() {
            this.page = 1;
            this.onLoad("refresh");
        },

        onLoad(type) {
            let params = {
                limit: this.limit,
                page: this.page,
                wx_member_id: localStorage.getItem('wx_member_id'),
                token: localStorage.getItem('token'),
                cate_id: 5,
            };
            this.$post("/api/finance/index", params)
                .then(res => {
                    if (res.code == 1) {
                        if (type == "refresh") {
                            this.listSource = res.data.dataList;
                            this.isLoading = false;
                            this.finished = false;
                        } else {
                            this.listSource = this.listSource.concat(
                                res.data.dataList
                            );
                        }
                        this.loading = false;
                        this.page++;
                        if (res.data.dataList.length < this.limit) {
                            this.finished = true;
                        }
                    }
                })
                .catch(err => {
                });
        },
        //确认开票
        showPop(item) {
            // if (item.is_invoice == 1) {
            //     this.$router.push(`/jrAdvisoryInvoice?id=${item.id}&name=${item.company_name}&price=${item.price}`)
            // }
            if (item.is_invoice == 2) {
                this.$router.push(`/confirmInvoice?id=${item.id}&cate_id=5&type=look`)
                return
            }
            this.$router.push(`/confirmInvoice?id=${item.id}&cate_id=5&type=set`)
        },
        //确认收款页
        goConfirmMoney(item) {
            // this.$router.push(`/jrAdvisoryConfirmMoney?id=${item.id}`)
            if (item.receive_state == 1) {
                this.$router.push(`/otherMoney?id=${item.id}&type=set`)
            }
            if (item.receive_state == 2) {
                this.$router.push(`/otherMoney?id=${item.id}&type=look`)
            }
        },
        //查看开票信息页
        goBillingInfo(item) {
            if (item.is_invoice == 2) {
                this.$router.push(`/jrAdvisoryBillingInfo?id=${item.id}`)
            }
        },
    },
    created() {
        this.button1 = this.$queryMenu('Finance/advisory')
    },
}
</script>

<style scoped lang="less">
.card-list {
    padding: 16px;
    padding-top: 0;

    .card {
        /*height: 200px;*/
        position: relative;
        color: #fff;
        margin-bottom: 15px;

        .card-top {
            display: flex;
            flex-wrap: wrap;
            background-size: 100% 100%;
            background-repeat: no-repeat;
            padding: 20px 30px;
            border-radius: 8px 8px 0 0;

            .card-title {
                display: flex;
                justify-content: space-between;
                width: 100%;
                margin-bottom: 13px;

                > div:nth-of-type(1) {
                    font-size: 16px;
                    font-weight: bold;
                    flex: 1;
                    padding-right: 10px;
                }

                > div:nth-of-type(2) {
                    font-size: 12px;
                    padding-left: 10px;
                }
            }

            .mtext-line {
                width: 50%;
                font-size: 13px;
                flex-wrap: wrap;
                overflow: hidden;
                text-overflow: ellipsis;
                white-space: nowrap;
            }

            .single-line {
                display: flex;
                justify-content: space-between;
                width: 100%;
                font-size: 13px;
                overflow: hidden;
                text-overflow: ellipsis;
                white-space: nowrap;

                text-overflow: -o-ellipsis-lastline;
                overflow: hidden;
                text-overflow: ellipsis;
                display: -webkit-box;
                -webkit-line-clamp: 1;
                -webkit-box-orient: vertical;

                margin-bottom: 10px;
            }

            > .mtext-line:not(:last-child) {
                margin-bottom: 10px;
            }
        }

        .card-btn {
            display: flex;
            justify-content: center;
            align-items: center;
            width: 100%;
            height: 60px;
            padding-left: 0;
            bottom: 8px;
            background-size: 100% 100%;
            background-repeat: no-repeat;

            div {
                height: 35px;
                width: 135px;
                margin: 0 8px;
                display: flex;
                align-items: center;
                justify-content: center;
                background: #fff;
                opacity: 0.8;
                color: #366cb3;
                border-radius: 5px;
                font-size: 14px;
            }

            .gray-color {
                background: #c8c8c8;
                color: #fff;
            }
        }
    }
}

.pop-window {
    background: rgba(0, 0, 0, 0.6);
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    height: 100vh;
    width: 100vw;
    z-index: 100;

    .pop-box {
        width: 80vw;
        height: 233px;
        margin-left: 10vw;
        background: #fff;
        border-radius: 5px;
        margin-top: 50%;
        display: flex;
        align-items: center;
        flex-direction: column;
        padding-top: 45px;
        position: relative;

        > img:nth-of-type(1) {
            width: 69px;
            height: 69px;
        }

        > img:nth-of-type(2) {
            width: 30px;
            height: 30px;
            position: absolute;
            bottom: -45px;
        }

        .tishi-text {
            font-size: 17px;
            color: #333333;
            padding: 20px 0;
        }

        .confirm-btn {
            width: 150px;
            height: 45px;
            background-image: linear-gradient(-83deg, #e61a1a 0%, #f33e3e 100%),
                linear-gradient(#ff6766, #ff6766);
            background-blend-mode: normal, normal;
            border-radius: 22px;
            display: flex;
            align-items: center;
            justify-content: center;
            color: #fefefe;
            font-size: 16px;
        }
    }
}
</style>